import BaseXform from '../base-xform';

class TableColumnXform extends BaseXform {
    get tag() {
        return 'tableColumn';
    }

    prepare(model, options) {
        model.id = options.index + 1;
    }

    render(xmlStream, model) {
        xmlStream.leafNode(this.tag, {
            id: model.id.toString(),
            name: model.name,
            totalsRowLabel: model.totalsRowLabel,
            totalsRowFunction: model.totalsRowFunction,
            dxfId: model.dxfId,
        });
        return true;
    }


    parseXmlObject(node) {
        if (node._name === this.tag) {
            this.model = {
                name: node._attributes.name,
                totalsRowLabel: node._attributes.totalsRowLabel,
                totalsRowFunction: node._attributes.totalsRowFunction,
                dxfId: node._attributes.dxfId,
            };
            return true;
        }
        return false
    }

    parseOpen(node) {
        if (node.name === this.tag) {
            const { attributes } = node;
            this.model = {
                name: attributes.name,
                totalsRowLabel: attributes.totalsRowLabel,
                totalsRowFunction: attributes.totalsRowFunction,
                dxfId: attributes.dxfId,
            };
            return true;
        }
        return false;
    }

    parseText() {
    }

    parseClose() {
        return false;
    }
}

export default TableColumnXform;
